package com.afd.ozblip.activity;

import java.util.HashMap;
import java.util.Map;

import com.afd.ozblip.util.SharedUtil;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.ToggleButton;

public class PrivacyActivity extends BaseActivity {

	/****************** 视图变量 **************************/
	private RadioGroup privacyRg;
	private RadioButton verifyRb;
	private RadioButton notAllowRb;
	private RadioButton allowRb;
	private ToggleButton nearbyTb;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.privacy);
		// 启动返回功能
		toBack();
		// 寻找视图
		findViews();
		// 设置监听
		setListeners();
		// 获取参数
		getBundle();
	}

	/**
	 * 寻找视图
	 */
	public void findViews() {
		this.privacyRg = (RadioGroup) findViewById(R.id.rg_privacy_group);
		this.verifyRb = (RadioButton) findViewById(R.id.rb_privacy_verify);
		this.notAllowRb = (RadioButton) findViewById(R.id.rb_privacy_notAllow);
		this.allowRb = (RadioButton) findViewById(R.id.rb_privacy_allow);
		this.nearbyTb = (ToggleButton) findViewById(R.id.tb_privacy_nearby);
		Map<String, Object> privacyInfo = SharedUtil.fetchPrivacyInfo(this);
		if (privacyInfo != null) {
			int verifyVal = (Integer) privacyInfo.get("verifyVal");
			if (verifyVal == 1) {
				this.verifyRb.setChecked(true);
			} else if (verifyVal == 2) {
				this.notAllowRb.setChecked(true);
			} else if (verifyVal == 3) {
				this.allowRb.setChecked(true);
			}
			boolean nearbyAllow = (Boolean) privacyInfo.get("nearbyAllow");
			this.nearbyTb.setChecked(nearbyAllow);
		}

	}

	/**
	 * 设置监听
	 */
	public void setListeners() {
		this.privacyRg
				.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

					@Override
					public void onCheckedChanged(RadioGroup group, int checkedId) {
						switch (checkedId) {
						case R.id.rb_privacy_verify:
							SharedUtil
									.storePrivacyInfo(PrivacyActivity.this, 1);
							break;
						case R.id.rb_privacy_notAllow:
							SharedUtil
									.storePrivacyInfo(PrivacyActivity.this, 2);
							break;
						case R.id.rb_privacy_allow:
							SharedUtil
									.storePrivacyInfo(PrivacyActivity.this, 3);
							break;

						default:
							break;
						}
					}
				});
		this.nearbyTb
				.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

					@Override
					public void onCheckedChanged(CompoundButton buttonView,
							boolean isChecked) {
						SharedUtil.storePrivacyInfo(PrivacyActivity.this,
								isChecked);
					}
				});
	}

	/**
	 * 获取传递的参数
	 */
	private void getBundle() {
		// Intent intent = getIntent();
	}

}